import axiosInstance from "./ajax"
import type { ResDataType } from "./ajax"

// 获取用户信息
export async function getUserInfoService(): Promise<ResDataType> {
    const url = "/api/user/info"
    const data = (await axiosInstance.get(url)) as ResDataType
    return data
}

// 注册用户(nickname可能没有值)
export async function registerService(username: string, password: string, nickname?: string): Promise<ResDataType> {
    const url = "/api/user/register"
    const body = { username, password, nickname: nickname || username }
    const data = (await axiosInstance.post(url, body)) as ResDataType
    return data
}

// 登录
export async function loginService(username: string, password: string): Promise<ResDataType> {
    const url = "/api/user/login"
    const body = { username, password }
    const data = (await axiosInstance.post(url, body)) as ResDataType
    return data
}
